<template>
	<el-submenu v-if="menu.list && menu.list.length >= 1" :index="menu.menuId + ''"
		:popper-class="'site-sidebar--' + sidebarLayoutSkin + '-popper'">
		<template slot="title">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</template>
		<sub-menu v-for="item in menu.list" :key="item.menuId" :menu="item" :dynamicMenuRoutes="dynamicMenuRoutes">
		</sub-menu>
	</el-submenu>
	<el-menu-item v-else :index="menu.menuId + ''" @click="gotoRouteHandle(menu)">
		<el-badge class="item" v-if="menu.menuId==183&&chatNumJjqz!=0" :value="chatNumJjqz">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge>
    <el-badge class="item" v-else-if="menu.menuId==34&&numberDtx!=0" :value="numberDtx">
    	<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
    	<span>{{ menu.name }}</span>
    </el-badge>
    <el-badge class="item" v-else-if="menu.menuId==77&&numberDrz!=0" :value="numberDrz">
    	<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
    	<span>{{ menu.name }}</span>
    </el-badge>
    <el-badge class="item" v-else-if="menu.menuId==99&&numberDts!=0" :value="numberDts">
    	<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
    	<span>{{ menu.name }}</span>
    </el-badge>
    <el-badge class="item" v-else-if="menu.menuId==149&&numberDtg!=0" :value="numberDtg">
    	<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
    	<span>{{ menu.name }}</span>
    </el-badge>
		<span v-else>
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</span>
	</el-menu-item>
</template>

<script>
	import SubMenu from './main-sidebar-sub-menu'
	export default {
		name: 'sub-menu',
		data() {
			return {
				chatNumJjqz: 0,
        numberDtx:0,
        numberDrz:0,
        numberDts:0,
        numberDtg:0,
			}
		},
		props: {
			menu: {
				type: Object,
				required: true
			},
			dynamicMenuRoutes: {
				type: Array,
				required: true
			}
		},
		components: {
			SubMenu
		},
		computed: {
			sidebarLayoutSkin: {
				get() {
					return this.$store.state.common.sidebarLayoutSkin
				}
			}
		},
		methods: {
			// 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
			gotoRouteHandle(menu) {
				var route = this.dynamicMenuRoutes.filter(item => item.meta.menuId === menu.menuId)
				if (route.length >= 1) {
					this.$router.push({
						name: route[0].name
					})
				}
			}
		},
		mounted() {
			setInterval(() => {
				if (this.$cookie.get('numberJjqz')) {
					this.chatNumJjqz = this.$cookie.get('numberJjqz')
				}

        if (this.$cookie.get('numberDtx')) {
        	this.numberDtx = this.$cookie.get('numberDtx')
        }
        if (this.$cookie.get('numberDrz')) {
        	this.numberDrz = this.$cookie.get('numberDrz')
        }
        if (this.$cookie.get('numberDts')||this.$cookie.get('numberDss')) {
        	this.numberDts = Number(this.$cookie.get('numberDts')) + Number(this.$cookie.get('numberDss'))
        }
        if (this.$cookie.get('numberDtg')) {
        	this.numberDtg = this.$cookie.get('numberDtg')
         }
			}, 1000)
		},
	}
</script>
<style>
	.item {
		/* margin-top: 10px;
		margin-right: 40px; */

	}

	.el-badge__content.is-fixed.is-dot {
		right: -5px;
		top: 20px;
	}
	.el-badge__content.is-fixed{
		right: 0px;
		top: 20px;
	}
</style>
